package com.eedi.framework.oauth2.controller.org;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.oauth2.controller.org.vo.client.OrgOAuth2ClientPageReqVO;
import com.eedi.framework.oauth2.controller.org.vo.client.OrgOAuth2ClientRespVO;
import com.eedi.framework.oauth2.controller.org.vo.client.OrgOAuth2ClientSaveReqVO;
import com.eedi.framework.oauth2.dal.dataobject.OrgOAuth2ClientDO;
import com.eedi.framework.oauth2.service.OrgOAuth2ClientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.eedi.framework.common.pojo.CommonResult.success;

//@Tag(name = "经营界面 - OAuth2 客户端")
//@RestController
//@RequestMapping("/oauth2-client")
//@Validated
public class OrgOAuth2ClientController {

    @Resource
    private OrgOAuth2ClientService orgOAuth2ClientService;

    @PostMapping("/create")
    @Operation(summary = "创建 OAuth2 客户端")
    @PreAuthorize("@ss.hasPermission('org:oauth2-client:create')")
    public CommonResult<String> createOAuth2Client(@Valid @RequestBody OrgOAuth2ClientSaveReqVO createReqVO) {
        return success(orgOAuth2ClientService.createOAuth2Client(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新 OAuth2 客户端")
    @PreAuthorize("@ss.hasPermission('orgtem:oauth2-client:update')")
    public CommonResult<Boolean> updateOAuth2Client(@Valid @RequestBody OrgOAuth2ClientSaveReqVO updateReqVO) {
        orgOAuth2ClientService.updateOAuth2Client(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除 OAuth2 客户端")
    @Parameter(name = "orgtemOauth2ClientId", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('orgtem:oauth2-client:delete')")
    public CommonResult<Boolean> deleteOAuth2Client(@RequestParam("orgtemOauth2ClientId") String orgtemOauth2ClientId) {
        orgOAuth2ClientService.deleteOAuth2Client(orgtemOauth2ClientId);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得 OAuth2 客户端")
    @Parameter(name = "orgtemOauth2ClientId", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('orgtem:oauth2-client:query')")
    public CommonResult<OrgOAuth2ClientRespVO> getOAuth2Client(@RequestParam("orgtemOauth2ClientId") String orgtemOauth2ClientId) {
        OrgOAuth2ClientDO client = orgOAuth2ClientService.getOAuth2Client(orgtemOauth2ClientId);
        return success(BeanUtils.toBean(client, OrgOAuth2ClientRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得 OAuth2 客户端分页")
    @PreAuthorize("@ss.hasPermission('orgtem:oauth2-client:query')")
    public CommonResult<PageResult<OrgOAuth2ClientRespVO>> getOAuth2ClientPage(@Valid OrgOAuth2ClientPageReqVO pageVO) {
        PageResult<OrgOAuth2ClientDO> pageResult = orgOAuth2ClientService.getOAuth2ClientPage(pageVO);
        return success(BeanUtils.toBean(pageResult, OrgOAuth2ClientRespVO.class));
    }

}
